<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateVOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('v_orders', function (Blueprint $table) {
            $table->increments('id');
            $table->string('order_no',32)->default('')->comment('订单编号');
            $table->uuid('owner_uuid')->comment('货主唯一标识');
            $table->uuid('sender_uuid')->comment('发货人唯一标识');
            $table->uuid('receiver_uuid')->comment('收货人唯一标识');
            $table->uuid('create_uuid')->comment('发单人唯一标识');
            $table->integer('route_id')->default(0)->comment('路线ID');
            $table->string('cargo_type',32)->default('')->comment('货物类型');
            $table->integer('price')->default(0)->comment('价格，单位：分');
            $table->tinyInteger('price_unit')->default(0)->comment('价格单位，1:元/吨,2:元/件,3:元/个,4:元/趟');
            $table->string('price_desc', 512)->default('')->comment('价格说明');
            $table->integer('loss_deduct')->default(-1)->comment('损耗扣款，-1没有扣款 1扣款');
            $table->integer('loss_limit')->default(0)->comment('最大损耗限制');
            $table->integer('loss_price')->default(0)->comment('超出部分扣款单价');
            $table->tinyInteger('loss_price_unit')->default(0)->comment('扣款单价单位，1:元/吨,2:元/件,3:元/个,4:元/趟');
            $table->integer('car_scheme_id')->default(0)->comment('车辆方案ID');
            $table->integer('total_car_num')->default(0)->comment('需要车辆总数');
            $table->integer('shipping_car_num')->default(0)->comment('已报名车辆数量');
            $table->string('order_remark', 512)->default('')->comment('运单备注');
            $table->dateTime('start_time')->comment('运单开始时间');
            $table->dateTime('end_time')->comment('运单结束时间');
            $table->tinyInteger('status')->default(10)->comment('订单状态，10已发布 20已完成 30已取消');
            $table->dateTime('finish_time')->nullable()->comment('完成时间');
            $table->dateTime('cancel_time')->nullable()->comment('取消时间');
            $table->timestamps();
            $table->index('order_no', 'idx_order_no');
            $table->index('sender_uuid', 'idx_sender_uuid');
            $table->index('route_id', 'idx_route_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('v_orders');
    }
}
